﻿using System;
using System.Text;
using System.Drawing;
using System.Buffers;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;

public static partial class glDRIVE
{
    /*
    连分式逐步插值
    double funpq(double x[],double y[],int n,double eps,double t)
    x：x[n]存放结点值x[0]～x[n-1]
    y">：y[n]存放结点函数值y[0]～y[n-1]
    n：n数据点个数。实际插值时最多取离插值点t最近的八个点。
    eps：精度要求
    t：t插值点值
    返回插值点t处的连分式函数值
    */

    public static string drive_funpq(int w, int h)
    {
        double t, z;
        double[] x = new double[10] { -1.0, -0.8, -0.65, -0.4, -0.3, 0.0, 0.2, 0.45, 0.8, 1.0 };
        double[] y = new double[10] { 0.0384615, 0.0588236, 0.0864865, 0.2, 0.307692, 1.0, 0.5, 0.164948, 0.0588236, 0.0384615 };

        int pk = 10;
        double[] px = new double[(x.Length - 1) * pk + 1];
        double[] py = new double[(x.Length - 1) * pk + 1];
        for (int i = 0; i < x.Length - 1; i++)
        {
            for (int j = 0; j <= pk; j++)
            {
                px[i * pk + j] = x[i] + (x[i + 1] - x[i]) * ((double)j / (double)pk);
                py[i * pk + j] = gl.funpq(x, y, 10, 0.0000001, px[i * pk + j]);
            }
        }

        return html_image(w, h, px, py,
            new double[] { -1.0, -0.5, 0.0, 0.5, 1.0 },
            new double[] { 0.0, 0.2, 0.4, 0.6, 0.8, 1.0 },
            x, y);
    }
}